/**
 * Agent Configuration Types
 * 
 * Defines the structure for agent configurations used in the Visual Agent Designer
 */

/**
 * Supported Claude models
 */
export type ClaudeModel = 
  | 'claude-opus-4'
  | 'claude-sonnet-4'
  | 'claude-sonnet-4.5'
  | 'claude-haiku-4';

/**
 * Context management strategies
 */
export type ContextStrategy = 'compact' | 'full' | 'custom';

/**
 * Workflow node types
 */
export type WorkflowNodeType = 
  | 'input'
  | 'processing'
  | 'tool_call'
  | 'subagent'
  | 'condition'
  | 'loop'
  | 'output';

/**
 * System prompt configuration
 */
export interface SystemPromptConfig {
  type: 'text' | 'preset';
  content: string;
  preset?: string;
}

/**
 * Tool configuration
 */
export interface ToolConfig {
  name: string;
  enabled: boolean;
  config?: Record<string, any>;
}

/**
 * Subagent configuration
 */
export interface SubagentConfig {
  id: string;
  name: string;
  description: string;
  enabled: boolean;
}

/**
 * Workflow node position
 */
export interface NodePosition {
  x: number;
  y: number;
}

/**
 * Workflow node data
 */
export interface WorkflowNodeData {
  label: string;
  description?: string;
  config?: Record<string, any>;
}

/**
 * Workflow node
 */
export interface WorkflowNode {
  id: string;
  type: WorkflowNodeType;
  position: NodePosition;
  data: WorkflowNodeData;
}

/**
 * Workflow edge (connection between nodes)
 */
export interface WorkflowEdge {
  id: string;
  source: string;
  target: string;
  label?: string;
  condition?: string;
}

/**
 * Agent settings
 */
export interface AgentSettings {
  maxTokens?: number;
  temperature?: number;
  contextStrategy: ContextStrategy;
  maxTurns?: number;
  includePartialMessages?: boolean;
}

/**
 * Complete agent configuration
 */
export interface AgentConfig {
  id: string;
  name: string;
  description: string;
  systemPrompt: SystemPromptConfig;
  model: ClaudeModel;
  tools: ToolConfig[];
  subagents: SubagentConfig[];
  workflow: {
    nodes: WorkflowNode[];
    edges: WorkflowEdge[];
  };
  settings: AgentSettings;
  createdAt: number;
  updatedAt: number;
  version: number;
}

/**
 * Agent template
 */
export interface AgentTemplate {
  id: string;
  name: string;
  description: string;
  category: string;
  config: Omit<AgentConfig, 'id' | 'createdAt' | 'updatedAt' | 'version'>;
  tags: string[];
  author?: string;
  isPublic: boolean;
}

/**
 * Agent execution context
 */
export interface AgentExecutionContext {
  agentId: string;
  sessionId: string;
  currentNodeId: string;
  variables: Record<string, any>;
  history: Array<{
    nodeId: string;
    timestamp: number;
    result: any;
  }>;
}

/**
 * Create agent request
 */
export interface CreateAgentRequest {
  name: string;
  description: string;
  systemPrompt: SystemPromptConfig;
  model: ClaudeModel;
  tools?: ToolConfig[];
  subagents?: SubagentConfig[];
  workflow?: {
    nodes: WorkflowNode[];
    edges: WorkflowEdge[];
  };
  settings?: Partial<AgentSettings>;
}

/**
 * Update agent request
 */
export interface UpdateAgentRequest {
  name?: string;
  description?: string;
  systemPrompt?: SystemPromptConfig;
  model?: ClaudeModel;
  tools?: ToolConfig[];
  subagents?: SubagentConfig[];
  workflow?: {
    nodes: WorkflowNode[];
    edges: WorkflowEdge[];
  };
  settings?: Partial<AgentSettings>;
}

/**
 * Agent list response
 */
export interface AgentListResponse {
  agents: AgentConfig[];
  total: number;
  page: number;
  pageSize: number;
}

/**
 * Workflow validation result
 */
export interface WorkflowValidationResult {
  valid: boolean;
  errors: Array<{
    nodeId?: string;
    edgeId?: string;
    message: string;
  }>;
  warnings: Array<{
    nodeId?: string;
    edgeId?: string;
    message: string;
  }>;
}

